//
//  YKSelectDrugItemCell.m
//  YunKang
//
//  Created by leoking870 on 2017/10/4.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKSelectDrugItemCell.h"
#import "YKDashView.h"
#import "KYVideoCheckBox.h"
@interface YKSelectDrugItemCell ()
@property (weak, nonatomic) IBOutlet UIView *checkBoxContainerView;
@property (weak, nonatomic) IBOutlet UILabel *drugNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *drugCountLabel;
@property (weak, nonatomic) IBOutlet UITextField *drugPriceInput;
@property (nonatomic, strong) KYVideoCheckBox* box;
@end


@implementation YKSelectDrugItemCell
@dynamic tableViewItem;
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.checkBoxContainerView.tf_weight = 1;
    self.drugNameLabel.tf_weight = 4;
    self.drugCountLabel.tf_weight = 2;
    self.drugPriceInput.tf_weight = 2;
    self.drugNameLabel.numberOfLines = 0;
    self.drugPriceInput.keyboardType = UIKeyboardTypeDecimalPad;
    self.drugCountLabel.textAlignment = NSTextAlignmentCenter;
    self.drugPriceInput.textAlignment = NSTextAlignmentCenter;
    self.drugNameLabel.textAlignment = NSTextAlignmentCenter;
    [@[self.checkBoxContainerView, self.drugNameLabel,  self.drugCountLabel,self.drugPriceInput] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.top.equalTo(self.contentView.mas_top).offset(11);
    }];
    
    [@[self.checkBoxContainerView, self.drugNameLabel,  self.drugCountLabel,self.drugPriceInput] mas_alignWeightlyAlongAxis:MASAxisTypeHorizontal
                                                                                                        fixedSpace:@2
                                                                                                         leadingTo:self.contentView.mas_leading
                                                                                                         leadSpace:13
                                                                                                        trailingTo:self.contentView.mas_trailing
                                                                                                         tailSpace:13];
    
    YKDashView* dashView = [[YKDashView alloc]init];
    dashView.lineWidth = .5f;
    dashView.lineColor = [UIColor tf_colorWithHexString:@"#d4d4d4"];
    dashView.dashLineLength = 3;
    [self addSubview:dashView];
    [dashView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.trailing.equalTo(self);
        make.height.mas_equalTo(1);
    }];
    
    KYVideoCheckBox* box = [[KYVideoCheckBox alloc]initWithFrame:CGRectMake(0, 0, 15, 15)];
    box.on = NO;
    [self.checkBoxContainerView addSubview:box];
    [box mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.checkBoxContainerView);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    [box addTarget:self action:@selector(onCheckBoxValueChanged:) forControlEvents:UIControlEventValueChanged];
    self.box = box;
//    [RACObserve(self.drugPriceInput, text) subscribeNext:^(id x) {
//        self.tableViewItem.model.drugprice = x;
//    }];
    
//    [self.drugPriceInput.rac_textSignal subscribeNext:^(id x) {
//        self.tableViewItem.model.DRUGPRICE = x;
//    }];
    
}

- (void)cellWillAppear {
    [super cellWillAppear];
//    self.drugNameLabel.text = self.tableViewItem.model.CINV_NAME;
    
    self.drugNameLabel.text = [NSString stringWithFormat:@"%@\n%@\n%@",self.tableViewItem.model.CINV_NAME,self.tableViewItem.model.CPACKINGTYPE,self.tableViewItem.model.CENTERPRISE];
    
    self.box.on = self.tableViewItem.selected;
    self.drugCountLabel.text = self.tableViewItem.model.WHOLE_PRICE;
//    self.drugPriceInput.text = self.tableViewItem.model.DRUGPRICE;
}

- (void)onCheckBoxValueChanged:(KYVideoCheckBox *)sender {
    self.tableViewItem.selected = sender.on;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
